package com.zjl.spring.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.zjl.spring.enums.DeleteEnums;
import org.apache.ibatis.reflection.MetaObject;

import java.time.LocalDateTime;

/*
 * 自动填充字段
 *
 * @Author zhuangjl
 * @Date 2021/11/10 18:53
 **/
public class CustomizeMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

        this.setFieldValByName("creator", "当前登陆人名称", metaObject);
        this.setFieldValByName("creatorId", "当前登陆人id", metaObject);
        this.setFieldValByName("createDt", LocalDateTime.now(), metaObject);

        this.setFieldValByName("lastUpdator", "当前登陆人名称", metaObject);
        this.setFieldValByName("lastUpdatorId", "当前登陆人id", metaObject);
        this.setFieldValByName("lastUpdateDt", LocalDateTime.now(), metaObject);

        this.setFieldValByName("deleted", DeleteEnums.NOT_DELETE.getValue(), metaObject);
    }

    @Override
    public void updateFill(MetaObject metaObject) {

        this.setFieldValByName("lastUpdator", "当前登陆人名称", metaObject);
        this.setFieldValByName("lastUpdatorId", "当前登陆人id", metaObject);
        this.setFieldValByName("lastUpdateDt", LocalDateTime.now(), metaObject);
    }

}
